package main.java.tmi.order.service.impl;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import main.java.tmi.common.service.impl.AbstractDao;
import main.java.tmi.order.service.OrderVO;

import org.springframework.stereotype.Repository;

/**
 * Asign Data Access Object
 *
 * @author min
 * @since 2010. 09. 10.
 */
@Repository
public class OrderDAO extends AbstractDao {
	
	/**
	 *
	 * @param realmCode
	 * @param odrId
	 * @return TestVO List
	 * @throws SQLException 
	 */

	public String getMaxOdrSeq(String ordNo1) throws SQLException {
		System.out.println("==================================ordNo1"+ordNo1 );
		String odrSeq = selectByPk("OrderDAO.getMaxOdrSeq", ordNo1).toString(); 
		return odrSeq;
	}
	
	
	public String orderDupChk(String ordNo1) throws SQLException {
		System.out.println("==================================ordNo1"+ordNo1 );
		String odrSeq = selectByPk("OrderDAO.orderDupChk", ordNo1).toString(); 
		return odrSeq;
	}
	
	
	public void  addOrder(Map<String, String> param) throws SQLException {
		insert("OrderDAO.addOrder", param);
	}
	
	public int  modifyOrder(Map<String, String> param) throws SQLException {
		return update("OrderDAO.modifyOrder", param);
	}
	

    public Map<String,String> getOrderView(Map<String,String> param){
    	Map<String,String> returnMap ;
        returnMap = (Map<String,String>) selectByPk("OrderDAO.getOrderView", param);
        
        return returnMap;
    }
    

	public int  deleteOrder(Map<String, String> param) throws SQLException {
		return delete("OrderDAO.deleteOrder", param);
	}
    /*====================== ODR DETAIL ==================*/
    	
	//조회
	public List<OrderVO> getOrderDetailList(Map<String,String> param) throws SQLException {
		return (List<OrderVO>) list("OrderDAO.getOrderDetailList", param);
	}

	public int  delOdrDetail(Map<String, String> param) throws SQLException {
		return delete("OrderDAO.delOdrDetail", param);
	}
	
    //등록
	public int addOrderDetail(Map<String, String> param) throws SQLException {
		System.out.println("==================================addDetail param"+param );
		insert("OrderDAO.addOrderDetail", param);
		return 1;
	}
	//수정
	public int  detailUpdate(Map<String, String> param) throws SQLException {
		return update("OrderDAO.detailUpdate", param);
	}
	
	public int  deleteOrderDet(Map<String, String> param) throws SQLException {
		return delete("OrderDAO.deleteOrderDet", param);
	}
	
  /*====================== ODR Division ==================*/
	//MAX
   public String getMaxOrdPseq(Map<String,String> param) throws SQLException {
        System.out.println("==================================getMaxOrdPseq Get Start");
        String maxOrdPseq = selectByPk("OrderDAO.getMaxOrdPseq", param).toString(); 
        return maxOrdPseq;
    }
	   
	//0일때 조회
	public List<OrderVO> getDefaultOrderDivisionList(Map<String,String> param) throws SQLException {
		return (List<OrderVO>) list("OrderDAO.getDefaultOrderDivisionList", param);
	}
	
	//0아닐 일때 조회
    public List<OrderVO> getLastOrderDivisionList(Map<String,String> param) throws SQLException {
        return (List<OrderVO>) list("OrderDAO.getLastOrderDivisionList", param);
    }
    
    //NEW일때
    public List<OrderVO> getNewOrderDivisionList(Map<String,String> param) throws SQLException {
        return (List<OrderVO>) list("OrderDAO.getNewOrderDivisionList", param);
    }
    
  //신규 저장
	public void addOrderDivisionDetail(Map<String, String> param) throws SQLException {
		System.out.println("==================================addOrderDivisionDetail param "+param );
		insert("OrderDAO.addOrderDivisionDetail", param); 
	}
	
	//수정
	public int modifyOrderDivisionDetail(Map<String, String> param) throws SQLException {
		System.out.println("==================================modifyOrderDivisionDetail param "+param );
		return update("OrderDAO.modifyOrderDivisionDetail", param); 
	}
	
	public int  deleteOrderDivisionDetail(Map<String, String> param) throws SQLException {
		return delete("OrderDAO.deleteOrderDivisionDetail", param);
	}

	public int  deleteOrderPdet(Map<String, String> param) throws SQLException {
		return delete("OrderDAO.deleteOrderPdet", param);
	}
    
   public String deleteOrderDivisionChk(Map<String,String> param) throws SQLException {
        System.out.println("==================================deleteOrderDivisionChk  Start");
        System.out.println("==================================deleteOrderDivisionChk  param"+param);
        String delChk = selectByPk("OrderDAO.deleteOrderDivisionChk", param).toString(); 
        return delChk;
    }
	
}
